remove duplicated code in ClientSideEncryption class
authorMatthieu Gallien <matthieu.gallien@nextcloud.com>
Thu, 6 Feb 2025 10:34:49 +0000 (11:34 +0100)
committerMatthieu Gallien <matthieu.gallien@nextcloud.com>
Fri, 7 Feb 2025 08:12:29 +0000 (09:12 +0100)
Signed-off-by: Matthieu Gallien <matthieu.gallien@nextcloud.com>
src/libsync/clientsideencryption.cpp
src/libsync/clientsideencryption.h

index a80268dada01f5df928ba568cf79ec859d2f4844..c65c6639a8fbe10b916112ce36b6a7652258ca7f 100644 (file)
@@ -1316,38 +1316,6 @@ void ClientSideEncryption::fetchPublicKeyFromKeyChain(const AccountPtr &account)
     job->start();
 }
 
-bool ClientSideEncryption::checkPublicKeyValidity(const AccountPtr &account) const
-{
-    QByteArray data = EncryptionHelper::generateRandom(64);
-
-    Bio publicKeyBio;
-    QByteArray publicKeyPem = account->e2e()->getPublicKey().toPem();
-    BIO_write(publicKeyBio, publicKeyPem.constData(), publicKeyPem.size());
-    auto publicKey = PKey::readPublicKey(publicKeyBio);
-
-    auto encryptedData = EncryptionHelper::encryptStringAsymmetric(account->e2e()->getCertificateInformation(), account->e2e()->paddingMode(), *account->e2e(), data);
-    if (!encryptedData) {
-        qCWarning(lcCse()) << "encryption error";
-        return false;
-    }
-
-    auto key = _encryptionCertificate.getEvpPrivateKey();
-
-    const auto decryptionResult = EncryptionHelper::decryptStringAsymmetric(account->e2e()->getCertificateInformation(), account->e2e()->paddingMode(), *account->e2e(), *encryptedData);
-    if (!decryptionResult) {
-        qCWarning(lcCse()) << "encryption error";
-        return false;
-    }
-    const auto decryptResult = QByteArray::fromBase64(*decryptionResult);
-
-    if (data != decryptResult) {
-        qCInfo(lcCse()) << "invalid private key";
-        return false;
-    }
-
-    return true;
-}
-
 bool ClientSideEncryption::checkEncryptionIsWorking() const
 {
     qCInfo(lcCse) << "check encryption is working before enabling end-to-end encryption feature";
@@ -2296,7 +2264,7 @@ void ClientSideEncryption::decryptPrivateKey(const AccountPtr &account, const QB
                 }
             }
 
-            if (!getPrivateKey().isNull() && checkPublicKeyValidity(account)) {
+            if (!getPrivateKey().isNull() && checkEncryptionIsWorking()) {
                 writePrivateKey(account);
                 writeCertificate(account);
                 writeMnemonic(account, [] () {});
index 75bb149c9f6eb1a61efed80c708231b2e1976e41..fd7f369af04de320e966ee09e9bc957ca3fac265 100644 (file)
@@ -395,7 +395,6 @@ private:
                               SUCCESS_CALLBACK nextCheck,
                               ERROR_CALLBACK onError);
 
-    [[nodiscard]] bool checkPublicKeyValidity(const AccountPtr &account) const;
     [[nodiscard]] bool checkServerPublicKeyValidity(const QByteArray &serverPublicKeyString) const;
     [[nodiscard]] bool sensitiveDataRemaining() const;